﻿//作者：MrLee
//时间：2011-8-23
//名称：通讯录管理
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');

FantastPlatform.UI.MailListForm = function (config) {
    Ext.apply(this, config);
    var openStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '../Service/MailList.aspx?Action=GetType'
        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'Name',
            fields: ['Name', 'Value']
        }),
        remoteStore: true
    });
    openStore.load();
    var openComboBox = new Ext.form.ComboBox({
        fieldLabel: '<font color="red">*</font>&nbsp;&nbsp;成员组',
        name: 'MailListType',
        hiddenName: 'MailListTypeId',
        store: openStore,
        displayField: 'Name',
        mode: 'remote',
        valueField: 'Value',
        allowBlank: false,
        editable: false,
        triggerAction: 'all',
        emptyText: '选择成员组',
        readOnly: true,
        width: 130
    });
    this.items = [{
        layout: 'column',
        border: false,
        labelSeparator: '：',
        items: [
        {
            columnWidth: 1,
            border: false,
            layout: 'form',
            items: [new Ext.form.TextField({
                fieldLabel: '姓名',
                name: 'Name',
                allowBlank: false,
                blankText: "姓名不能为空",
                anchor: '90%'
            })]
        }, {
            columnWidth: 1,
            border: false,
            layout: 'form',
            items: [new Ext.form.TextField({
                fieldLabel: '手机号码',
                name: 'PhoneNumber',
                anchor: '90%'
            })]
        }, {
            columnWidth: 1,
            border: false,
            layout: 'form',
            items: [new Ext.form.TextField({
                fieldLabel: 'QQ号码',
                name: 'QQ',
                anchor: '90%'
            })]
        }
//        , {
//            columnWidth: 1,
//            border: false,
//            layout: 'form',
//            items: [new Ext.form.TextField({
//                fieldLabel: '地址',
//                name: 'Address',
//                allowBlank: false,
//                blankText: "地址不能为空",
//                anchor: '90%'
//            })]
//        }
        , {
            columnWidth: 1,
            border: false,
            layout: 'form',
            items: [openComboBox]
        }, {
            columnWidth: 1,
            border: false,
            layout: 'form',
            items: [new Ext.form.TextField({
                fieldLabel: '描述',
                name: 'Description',
                anchor: '90%'
            })]
        }
        ]
    }
    ];

    FantastPlatform.UI.MailListForm.superclass.constructor.call(this, {
        bodyStyle: 'padding:5px',
        collapsible: true,
        labelAlign: 'right',
        width: 390,
        autoScroll: true,
        border: false
    });
};

Ext.extend(FantastPlatform.UI.MailListForm, Ext.form.FormPanel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.MailListForm.superclass.onRender.call(this, ct, position);
        if (this.Id && this.Id != 0) {
            this.add(new Ext.form.Hidden({ name: 'Id', value: this.Id }));
            var maillistform = this.form
            var maillistId = this.Id
            openStore.reload({ callback: function (form, action) {
                maillistform.load({
                    url: '../Service/MailList.aspx?Action=Get',
                    params: { id: maillistId },
                    waitMsg: '正在读取数据...',
                    waitTitle: '请稍后...',
                    failure: function (form, action) {
                        if (action.failureType != 'client') {
                            showErrorMessage('操作失败', action.result.message, '');
                        }
                    }
                });
            }
            });

        }
    }
});
